-- ================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters 
-- command (Ctrl-Shift-M) to fill in the parameter 
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		duylv
-- Create date: 
-- Description:	
-- =============================================
ALTER PROCEDURE DeleteOrder 
	-- Add the parameters for the stored procedure here
	@OrderID int = 0
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
    -- Insert statements for procedure here
	BEGIN TRANSACTION
		UPDATE	[Order]
		SET		IsDelete = 1
		WHERE	[Order].OrderID = @OrderID
		SAVE TRANSACTION SaDeleteOrder
		IF @@ERROR <> 0 ROLLBACK TRANSACTION SaDeleteOrder
		UPDATE	MaterialLoaf
		SET		IsDelete = 1
		WHERE	MaterialLoaf.OrderID = @OrderID
		IF @@ERROR <> 0 ROLLBACK TRANSACTION SaDeleteOrder
		UPDATE	ProductLoaf
		SET		IsDelete = 1
		WHERE	ProductLoaf.OrderID = @OrderID
		IF @@ERROR <> 0 ROLLBACK TRANSACTION SaDeleteOrder
	COMMIT TRANSACTION
END
GO

/*
USE
WarehouseManagement
GO
EXEC DeleteOrder 2
*/